/**
 * Created by Administrator on 2016/10/19.
 */
$(function(){
    var index = document.getElementById('index');
    var pro_list = document.getElementById('pro_list');
    if(index){
        //page_id("index");
        cmjs.index('wish/index/doorTodoorService');
    }else if(pro_list){
        var page_index = 1;
        var page_size  = 12;
        var category_id = publicJs.getQueryString('id');
        var obj = {
            category_id:category_id,
            page_index:page_index,
            page_size:page_size
        }
        cmjs.pro_list('memberCenter/doorList',obj);
        $(document).on('click','.pro_list ul li',function(){
            var id = $(this).data('id');
           location.href = 'projecdetail.html?id='+id
        });
    }

});

cmjs = {
    //首页
    index : function(url,data){
        publicJs.get(url,data,function(res){
            if(res.ret==0){
                console.log(res);
                var d = res.data;
                new Vue({
                    el:'#index',
                    data:{
                        top: d.top,
                        center: d.center
                    },
                    methods:{
                        jump: function(url,id){

                            location.href = url+'?id='+id
                        }
                    }
                });
            }else{
                console.log(res.msg);
            }
        });
    },
    //    项目详情
    project_detail : function(url,data){
        publicJs.get(url,data,function(res){
            if(res.ret==0){
                console.log(res);
                var data = res.data;
                publicJs.modify_wx_tit(data.category_name);
                $('.projecdetail .content').html(data.editor_detail);
                $('body').attr('data-id',data.door_id);
            }
            else{
                console.log(res.msg);
            }
        });
    },
    pro_list : function(url,data){
        publicJs.get(url,data,function(res){
            if(res.ret==0){
                console.log(res);
                var list = res.data;
                if(list.length<data.page_size){
                    $('.infinite-scroll-preloader .preloader').remove();
                    myApp.detachInfiniteScroll($$('.infinite-scroll'));
                }
                $.each(list,function(i,t){
                    $('.pro_list ul').append('<li data-id="'+ t.door_id+'"><img src="'+t.pic+'" alt=""><div class="infor"><p class="name">'+ t.door_name+'</p><p class="price">'+ t.total_amount+'元/'+ t.minute+'分钟</p></div></li>');
                });
            }
            else{
                console.log(res.msg);
            }
        });
    }
}